package interpreter;

import java.awt.geom.Arc2D;

import composite.ObjectItem;

/**
 * Composite pattern and interpreter and template pattern mix.
 * Defines BasicObject, this object can not hold any other objects.
 */
@SuppressWarnings("serial")
public class PrimitiveArch extends PrimitiveAbstract implements ObjectItem{	
	int startX, startY, w, h;
	int startAngle, extAngle;

	/**
	 * Arch primitive constructor
	 */
	public PrimitiveArch(int startX, int startY, int w, int h, int startAngle, int extAngle){
		type = "arch";
		this.startX = startX;
		this.startY = startY;
		this.w = w;
		this.h = h;
		this.startAngle = startAngle;
		this.extAngle = extAngle;
		
		//Initial position
		posX = 0;
		posY = 0;
		
		createShape();
	}
	
	public void scale(double scaleX , double scaleY){
    	if(scaleX <= 0.1)
    		scaleX = 0.1;
    	if(scaleY <= 0.1)
    		scaleY = 0.1;
    	
    	this.scaleX = scaleX;
    	this.scaleY = scaleY;

		createShape();
	}
		
	protected void createShape(){
		shape = new Arc2D.Double(startX* scaleX + posX , startY * scaleY + posY, w * scaleX, h * scaleY, startAngle, extAngle, Arc2D.OPEN);
	}
		
	/**
	 * Create a copy of the primitive shape, to avoid references issues for not base(int etc.) types
	 */
	public PrimitiveArch clone(){
		PrimitiveArch archCopy = new PrimitiveArch(startX, startY, w, h, startAngle, extAngle);
		archCopy.color = color;
		archCopy.scaleX = scaleX;
		archCopy.scaleY = scaleY;
		archCopy.moveObject(posX, posY);
		return archCopy;
	}	
}
